/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-10-29
 * Time: 14:37
 */
class Test {
    public int count = 0;
    public synchronized void add()  {
        count++;
    }
    public int get() {
        return count;
    }
}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Test test = new Test();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                test.add();
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                test.add();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(test.get());
    }
}
